package org.dromara.easyai.extensions.solon.test.controller;

import org.dromara.easyai.matrixTools.Matrix;
import org.dromara.easyai.matrixTools.MatrixOperation;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Mapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: wen.y
 * @date: 2025/6/23
 */
@Mapping("/matrix")
@Controller
public class MatrixController {
	private static final Logger logger = LoggerFactory.getLogger(MatrixController.class);


	/**
	 * <pre>
	 * 0:[23.0,34.0,45.0]
	 * 1:[33.0,42.0,51.0]
	 * 2:[13.0,20.0,27.0]
	 * </pre>
	 * @return
	 * @throws Exception
	 */
	@Get
	@Mapping("/mul11")
	public String mul1() throws Exception {
		MatrixOperation matrixOperation = new MatrixOperation();
		Matrix m1 = new Matrix(3, 2);
		m1.setAll("[7,4]#[1,8]#[5,2]");

		Matrix m2 = new Matrix(2, 3);
		m2.setAll("[1,2,3]#[4,5,6]");
		Matrix m3 = matrixOperation.mulMatrix(m1, m2);
		logger.info("result={}", m3.getString());

		return m3.getString();
	}

	/**
	 * <pre>
	 * 0:[24.0,26.0]
	 * 1:[63.0,68.0]
	 * </pre>
	 * @return
	 * @throws Exception
	 */
	@Get
	@Mapping("/mul12")
	public String mul2() throws Exception {
		MatrixOperation matrixOperation = new MatrixOperation();
		Matrix m1 = new Matrix(3, 2);
		m1.setAll("[7,4]#[1,8]#[5,2]");

		Matrix m2 = new Matrix(2, 3);
		m2.setAll("[1,2,3]#[4,5,6]");
		Matrix m3 = matrixOperation.mulMatrix(m2, m1);
		logger.info("result={}", m3.getString());

		return m3.getString();
	}

	/**
	 * <pre>
	 * 0:[9.0,4.0,9.0,5.0,10.0,5.0]
	 * 1:[21.0,10.0,21.0,14.0,25.0,14.0]
	 * 2:[33.0,16.0,33.0,23.0,40.0,23.0]
	 * 3:[45.0,22.0,45.0,32.0,55.0,32.0]
	 * 4:[57.0,28.0,57.0,41.0,70.0,41.0]
	 * 5:[69.0,34.0,69.0,50.0,85.0,50.0]
	 * </pre>
	 * @return
	 * @throws Exception
	 */
	@Get
	@Mapping("/mul21")
	public String mul21() throws Exception {
		MatrixOperation matrixOperation = new MatrixOperation();
		Matrix m1 = new Matrix(6, 3);
		m1.setAll("[1,2,3]#[4,5,6]#[7,8,9]#[10,11,12]#[13,14,15]#[16,17,18]");

		Matrix m2 = new Matrix(3, 6);
		m2.setAll("[1,1,1,2,2,2]#[1,0,1,0,1,0]#[2,1,2,1,2,1]");
		Matrix m3 = matrixOperation.mulMatrix(m1, m2);
		logger.info("result={}", m3.getString());

		return m3.getString();
	}

	/**
	 * <pre>
	 * 0:[90.0,99.0,108.0]
	 * 1:[21.0,24.0,27.0]
	 * 2:[72.0,81.0,90.0]
	 * </pre>
	 * @return
	 * @throws Exception
	 */
	@Get
	@Mapping("/mul22")
	public String mul22() throws Exception {
		MatrixOperation matrixOperation = new MatrixOperation();
		Matrix m1 = new Matrix(6, 3);
		m1.setAll("[1,2,3]#[4,5,6]#[7,8,9]#[10,11,12]#[13,14,15]#[16,17,18]");

		Matrix m2 = new Matrix(3, 6);
		m2.setAll("[1,1,1,2,2,2]#[1,0,1,0,1,0]#[2,1,2,1,2,1]");
		Matrix m3 = matrixOperation.mulMatrix(m2, m1);
		logger.info("result={}", m3.getString());

		return m3.getString();
	}
}
